home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15519 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: help with queue
  5. Date: 19 Apr 1996 15:01:32 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4l89sc$kf6@sparcserver.lrz-muenchen.de>
  9. References: <4l73q1$148@itsop2.its.brooklyn.cuny.edu>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. dzielins@its.brooklyn.cuny.edu (Daniel Zielinski) writes:
  13.  
  14. >Could anybody help me with QUEUE structure? It's node based.
  15. >It seems that assert function fails (It's in the removeQueue function)
  16. >Whenever I try to remove something from a QUEUE I get:
  17. > line 31 in QUEUE.c assert failed.
  18. >Any clues on what I'm doing wrong would be apriciated.
  19.  
  20. >this is QUEUE.c     
  21.  
  22. >#include "QUEUE.h"
  23. >#include <assert.h>
  24. >#include <stdio.h>
  25.  
  26. [insertQueue edited]
  27.  
  28. >int
  29. >emptyQueue(Queue q) {
  30. >    assert((q.front==NULL && q.rear==NULL) || (q.front!=NULL && 
  31. >        q.rear!=NULL)); 
  32. >    return q.front==NULL;
  33. >}
  34.  
  35. This function obviously checks whether a queue is empty or not. It
  36. returns 1 if the queue is empty, 0 if it is not empty.
  37.  
  38. >DataType
  39. >removeQueue(Queue *qp) {
  40. >    Node *np;
  41. >    DataType d;
  42.  
  43. >    assert(!emptyQueue(*qp));     <-------- THIS IS THE LINE    
  44.  
  45. The implementor of your queues states that his removeQueue() function
  46. is not able to remove something from an empty queue. Since (s)he 
  47. wants to return the value of the removed node, this is a sane 
  48. assumption.
  49.  
  50. >    np=qp->front;
  51. >    d=np->data;
  52. >    qp->front=np->next;
  53. >    if (qp->front==NULL)
  54. >        qp->rear=NULL;
  55. >    deleteNode(np);
  56. >    return d;
  57. >}
  58.  
  59. >void
  60. >initQueue(Queue *qp) {
  61. >    qp->front=qp->rear=NULL;
  62. >}
  63.  
  64. This creates an empty queue. Your implementation of a queue assumes
  65. that only queues that are not empty can be passed to removeQueue().
  66.  
  67. Kurt
  68. --
  69. | Kurt Watzka                             Phone : +49-89-2180-6254
  70. | watzka@stat.uni-muenchen.de
  71.